package com.learngittesting.dsnTest;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 文件输入输出
 * @author DongSinan
 * @date 2022/2/17 15:54
 */
public class FileTest {

    File file = new File("src/main/java/com/learngittesting/dsnTest/file.txt");


    /**
     * 读取字节输出到控制台
     */
    public void fileTest()
    {

        try (FileInputStream fileInputStream = new FileInputStream(file)) {
          byte bytes[]=new byte[4];

          int readCount=0;

          while ((readCount=fileInputStream.read(bytes))!=-1)
          {
              System.out.print(new String(bytes,0,readCount));
          }

        } catch (FileNotFoundException e) {
            System.out.println("FileNotFoundException:"+e);
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IOException:"+e);
            e.printStackTrace();
        }
    }

}
